<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>活动管理</title>
    <#include "/include/resource.html"/>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "/include/header.html"/>
    <!-- Left side column. contains the logo and sidebar -->
    <#include "/include/main-sidebar.html"/>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                优惠活动
                <small>Add</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a href="#">活动管理</a></li>
                <li class="active">优惠活动</li>
            </ol>
        </section>
        <!-- 货物类型表单 -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">优惠活动</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form id= "advertisingForm" role="form" action="${base}/admin/admin_advertising/save" method="post">
                <input type="hidden" name="id" value="${(advertising.id)!''}">
                <input type="hidden" name="createDateString" value="${(advertising.createDateString)!''}">
                <input type="hidden" name="createUser" value="${(advertising.createUser)!''}">
                <input type="hidden" name="status" value="${(advertising.status)!''}">
                <#if valid??>
                    <input type="hidden" name="valid" value="${(advertising.valid)?c}">
                </#if>
                <div class="box-body">
                    <div class="form-group">
                        <label for="title">标题</label>
                        <input type="text" value="${(advertising.title)!''}" class="form-control" name="title" id="title" placeholder="标题">
                    </div>
                    <div class="form-group">
                        <label for="title">类别</label>
                        <select name="productType" class="form-control select">
                            <#list productTypeList as prod>
                                <option value="${prod.name}" <#if ((advertising.productType)!'')==prod.name>selected</#if>>${prod.name}</option>
                            </#list>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="title">选择商户</label>
                        <select name="merchantId" class="form-control select2 select2-hidden-accessible" style="width: 100%;">
                            <#list merchantList as prod>
                                <option value="${prod.id}" <#if ((advertising.merchantId)!0)==prod.id>selected</#if>>${prod.name}</option>
                            </#list>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="phone">联系方式</label>
                        <input type="text" value="${(advertising.phone)!''}" class="form-control" name="phone" id="phone" placeholder="联系方式">
                    </div>
                    <div class="form-group">
                        <label for="position">地址</label>
                        <input type="text" value="${(advertising.position)!''}" class="form-control" name="position" id="position" placeholder="地址">
                    </div>
                    <div class="form-group">
                        <label for="position">排序</label>
                        <input type="text" value="${(advertising.orderNo)!''}" class="form-control" name="orderNo" id="orderNo" placeholder="排序">
                    </div>
                    <div class="form-group">
                        <label for="introduction">简介</label>
                        <textarea  class="form-control" name="introduction" id="introduction" placeholder="标题">${(advertising.introduction)!''}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputFile">标题图</label>
                        <div class="row">

                            <div class="col-xs-2" style="width: 12%;">
                                <input type="file" id="exampleInputFile" multiple="multiple">
                            </div>
                            <div class="col-xs-2">
                                <input type="button" value="上传" onclick="pushImg()">
                            </div>
                        </div>
                        <input type="hidden" id="titleImg" name="titleImg" value="${(advertising.titleImg)!''}">
                        <p class="help-block">请选择所上传文件,点击上传按钮.</p>
                    </div>
                    <div class="timeline-body">
                        <img src="${(advertising.titleImg)!'http://placehold.it/150x100'}" alt="..." id="titleImage" class="margin">
                    </div>
                    <div class="box box-info">
                        <div class="box-header">
                            <h3 class="box-title">内容
                                <small>优惠活动内容</small>
                            </h3>
                            <!-- /. tools -->
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body pad">
                    <textarea id="txt" name="txt" rows="10" cols="80">
                        ${(advertising.txt)!''}
                    </textarea>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" onclick="$('#advertisingForm').submit();" class="btn btn-primary">Save</button>
                </div>
            </form>
        </div>
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.4.0
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="https://adminlte.io">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>
    <div class="control-sidebar-bg"></div>
</div>
<#include "/include/js_footer.html"/>
<!-- CK Editor -->
<script src="${base}/bower_components/ckeditor/ckeditor.js"></script>
<script>
    $(function () {
        $('.select2').select2()
        CKEDITOR.replace('txt')
        $('.textarea').wysihtml5()
    })

    function pushImg(obj) {

        var url = '${base}'+ "/admin/admin_advertising/titleImgeUpload"; //访问控制器是upload，后面必须加'/'否则会报错"org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.Mult...",但是如果是多级的URL【例如XX/XXX/00/upload/0】又没问题了.
        var files = $("#exampleInputFile").get(0).files[0]; //获取file控件中的内容

        var fd = new FormData();
        fd.append("uploadFile", files);
        $.ajax({
            type: "POST",
            contentType:false, //必须false才会避开jQuery对 formdata 的默认处理 , XMLHttpRequest会对 formdata 进行正确的处理
            processData: false, //必须false才会自动加上正确的Content-Type
            url: url,
            data: fd,
            success: function (msg) {

                var obj = eval('(' + JSON.stringify(msg) + ')');
                if(obj.SUCESS){
                    //填充图片
                    $("#titleImage").attr("src", obj.DATA);
                    $("#titleImage").css("width","150");
                    $("#titleImage").css("height","100");
                    //写入隐藏域
                    $("#titleImg").val(obj.DATA);
                }
            },
            error: function (msg) {
                //debugger;
                alert("error");
            }
        });
    }
</script>
</body>
</html>
